import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_myshop/common/constant.dart';
import 'package:flutter_myshop/pages/category.dart';
import 'package:flutter_myshop/pages/home.dart';
import 'package:flutter_myshop/pages/member.dart';
import 'package:flutter_myshop/pages/shopping_car.dart';
import 'package:flutter_myshop/provide/applicaiton.dart';
import 'package:flutter_myshop/provide/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

/*
 * 导航栏组件
 */
class IndexPage extends StatelessWidget {
  final List<Widget> tabBodies = [
    HomePage(),
    CategoryPage(),
    ShoppingCar(),
    MemberPage()
  ];

  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), title: Text('首页')),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.search), title: Text('分类')),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.shopping_cart), title: Text('购物车')),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.profile_circled), title: Text('会员中心')),
  ];

  @override
  Widget build(BuildContext context) {
    // 初始化屏幕数据
    ScreenUtil.init(context,
        width: Constant.MAX_WIDTH_SCREEN, height: Constant.MAX_HEIGHT_SCREEN);

    return Container(
      child: Provide<CurrentIndexProvider>(
        builder: (context, child, item) {
          return Scaffold(
            // 背景色
            backgroundColor: Color.fromRGBO(244, 246, 246, 1),
            // 底部导航栏
            bottomNavigationBar: BottomNavigationBar(
              backgroundColor: Colors.white,
              unselectedItemColor: Colors.blue,
              fixedColor: Colors.red,
              type: BottomNavigationBarType.fixed,
              items: bottomTabs,
              currentIndex: item.currentIndex,
              onTap: (index) {
                ProviderApplication.currentIndexProvider.changeIndex(index);
              },
            ),
            body: IndexedStack(
              index: item.currentIndex,
              children: tabBodies,
            ),
          );
        },
      ),
    );
  }
}
